﻿package com.designoutput.ui.newControls
{
    import com.designoutput.utils.Globals;
    
    import flash.events.*;

    public class DialogBox extends Box
    {
		override protected function initialize():void {
			super.initialize();
			
			showCloseButton = true;
		}
		
		public function show(modal:Boolean, transparentModal:Boolean = false):void {
			if(this.parent != null)
				return;
			
			Globals.popupManager.addPopup(this, modal, transparentModal);
			Globals.popupManager.center(this);
			
			this.addEventListener(KeyboardEvent.KEY_UP, keyUp, false, 0, true);
		}

        public function close():void
        {
			if(this.parent == null)
				return;
			
			this.removeEventListener(KeyboardEvent.KEY_UP, keyUp, false);
			
			Globals.popupManager.removePopup(this);
        }
		
		private function keyUp(event:KeyboardEvent) : void
		{
			if (event.keyCode == 13)
			{
				this.onConfirmKey();
			}
			else if (event.keyCode == 27)
			{
				this.onCancelKey();
			}
		}
		
		protected function onCancelKey():void {
			
		}
		
		protected function onConfirmKey():void {
			
		}
    }
}
